package com.haoe.dynamicproxy;

import java.lang.reflect.Proxy;

/**
 * @Author: 80305082
 * @Date: 2021/4/21
 * @Description: 动态代理实行测试类
 */
public class ProxyTest {
    public static void main(String[] args) {
        SuperMan superMan = new SuperMan();
        ProxyHandler proxyHandler = new ProxyHandler(superMan);
        Human instance = (Human) Proxy.newProxyInstance(superMan.getClass().getClassLoader(), superMan.getClass().getInterfaces(), proxyHandler);
        String believe = instance.believe();
        System.out.println(believe);
        System.out.println("**********************");
        instance.eat("火锅");
        System.out.println("===============================");
        CircleBedImpl circleBed = new CircleBedImpl();
        ProxyHandler proxyHandler1 = new ProxyHandler(circleBed);
        Bed bed = (Bed) Proxy.newProxyInstance(circleBed.getClass().getClassLoader(), circleBed.getClass().getInterfaces(), proxyHandler1);
        bed.shape("circle");
        bed.function("睡觉");
        System.out.println("------------------------------");
        SquareBedImpl squareBed = new SquareBedImpl();
        ProxyHandler proxyHandler2 = new ProxyHandler(squareBed);
        Bed bed2 = (Bed) Proxy.newProxyInstance(squareBed.getClass().getClassLoader(), squareBed.getClass().getInterfaces(), proxyHandler2);
        bed2.shape("square");
        bed2.function("睡觉觉");

    }
}
